package dynamic.util;

import com.baomidou.mybatisplus.generator.config.rules.DbColumnType;
import com.baomidou.mybatisplus.generator.config.rules.IColumnType;

import java.math.BigDecimal;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

public class TypeTranslate {

    private static final Map<IColumnType, Class<?>> typeMap = new HashMap<>();

    static {
        typeMap.put(DbColumnType.OBJECT, String.class);
        typeMap.put(DbColumnType.LONG, Long.class);
        typeMap.put(DbColumnType.BYTE_ARRAY, String.class); //$NON-NLS-1$
        typeMap.put(DbColumnType.BASE_BYTE, String.class);
        typeMap.put(DbColumnType.BASE_SHORT, String.class);
        typeMap.put(DbColumnType.BASE_CHAR, String.class);
        typeMap.put(DbColumnType.BASE_INT, String.class);
        typeMap.put(DbColumnType.BASE_LONG, String.class);
        typeMap.put(DbColumnType.BASE_FLOAT, String.class);
        typeMap.put(DbColumnType.BASE_DOUBLE, String.class);
        typeMap.put(DbColumnType.BASE_BOOLEAN, String.class);
        typeMap.put(DbColumnType.BYTE, String.class);
        typeMap.put(DbColumnType.BOOLEAN, Boolean.class);
        typeMap.put(DbColumnType.SHORT, String.class);
        typeMap.put(DbColumnType.CHARACTER, String.class);
        typeMap.put(DbColumnType.INTEGER, String.class);
        typeMap.put(DbColumnType.FLOAT, String.class);
        typeMap.put(DbColumnType.DOUBLE, String.class);
        typeMap.put(DbColumnType.STRING, String.class);
        typeMap.put(DbColumnType.DATE_SQL, java.sql.Date.class);
        typeMap.put(DbColumnType.TIME, java.sql.Time.class);
        typeMap.put(DbColumnType.TIMESTAMP, java.sql.Timestamp.class);
        typeMap.put(DbColumnType.BLOB, java.sql.Blob.class);
        typeMap.put(DbColumnType.CLOB, java.sql.Clob.class);
        typeMap.put(DbColumnType.LOCAL_DATE, java.time.LocalDate.class);
        typeMap.put(DbColumnType.LOCAL_TIME, java.time.LocalTime.class);
        typeMap.put(DbColumnType.YEAR, java.time.Year.class);
        typeMap.put(DbColumnType.YEAR_MONTH, java.time.YearMonth.class);
        typeMap.put(DbColumnType.LOCAL_DATE_TIME, java.time.LocalDateTime.class);
        typeMap.put(DbColumnType.INSTANT, java.time.Instant.class);
        typeMap.put(DbColumnType.MAP, java.util.Map.class);
        typeMap.put(DbColumnType.DATE, java.util.Date.class);
        typeMap.put(DbColumnType.BIG_INTEGER, java.math.BigInteger.class);
        typeMap.put(DbColumnType.BIG_DECIMAL, java.math.BigDecimal.class);

    }

    public static Class<?> getClassByType(IColumnType type) {
        return typeMap.get(type);
    }
}
